//赋值运算符重载
#include <iostream>
using namespace std;
class Person{
public:
    int *x;//指针--在堆区开辟
    Person(int x){
        this->x=new int(x);
    }
    ~Person(){
        if(x!=NULL){
            delete x;
            x=NULL;
        }
    }
    Person& operator=(Person &p){
        if(this->x!=NULL){//将左操作数清空
            delete x;
            x=NULL;
        }
        this->x = new int ((*p.x));//深拷贝操作
        return *this;
    }
};
int main()
{
    Person p1(18);
    Person p2(20);
    cout<<*(p1.x)<<endl;
    cout<<*(p2.x)<<endl;
    p1=p2;
    return 0;
}